<?php
namespace App\Api\Repositories\Log;

use App\Models\Log\LogPayShowContact as Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;

class LogPayShowContactRepositories{
    protected $eloquentClass = Model::class;

    public function create_data($order_id, $uid, $search_id, $type){
        return $this->eloquentClass::updateOrCreate([
            'uid'=> $uid,
            'search_id'=> $search_id,
            'type'=> $type,
        ], [
            'id'=> $order_id,
            'status'=> 0
        ]);
    }

    public function use_id_get_data($id){
        return $this->eloquentClass::where('id', $id)->first();
    }

    /**
     * 修改某些字段
     *
     * @param [type] $obj
     * @param array $field_values
     * @return void
     */
    public function update_fields($obj, $field_values=[]){
        foreach($field_values as $field=> $value){
            $obj->$field = $value;
        }
        return $obj->save();
    }

    /**
     * 获取支付的状态
     *
     * @param [type] $uid
     * @param [type] $search_id
     * @param [type] $type
     * @return void
     */
    public function get_data_status($uid, $search_id, $type){
        return $this->eloquentClass::where('uid', $uid)->where('search_id', $search_id)->where('type', $type)->value('status');
    }
}